package online.sh.cn.fy.common.utils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.map.HashedMap;
	


public class TokenUtils {
	private  Connection conn;  
    private  PreparedStatement  st; 
    private  ResultSet rs;
    private  Map<Object,Object> map;
    private  List<Object> list;
    
    public static String getSystime(){
    	String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime());
    	return time;
    } 
    
    public static String getSystimeSign(){
    	String time = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
    	return time;
    }
    
  //更新插入shtoken进入数据库
    public void updateshAccessToken(String accesstoken){
    	JDBCUtil ju=new JDBCUtil();
    	conn=ju.connect();
		try {
			String sql="update shtoken set token=?,time=?";
			st=(PreparedStatement) conn.prepareStatement(sql); 
			st.setString(1, accesstoken);
			st.setString(2, getSystime());
			st.executeUpdate();
			System.out.println("更新shtoken成功！");
		} catch (SQLException e) {  
            System.out.println("更新shtoken失败！" + e.getMessage());
		} finally {
			try {
				conn.close();
				st.close();
			} catch (SQLException e) {
				System.out.println("连接池关闭失败！");
			}
		}
    }
    
    //取出shtoken
    public String getshAccesstoken(){
    	String result="";
    	JDBCUtil ju=new JDBCUtil();
		conn=ju.connect();
		try {  
            String sql = "select * from shtoken";  
            st = (PreparedStatement) conn.prepareStatement(sql);  
            rs = st.executeQuery();
            while (rs.next()) {
            	result=rs.getString("token");
            }
            return result;
        } catch (SQLException e) {  
            System.out.println("获取shtoken值失败："+e.getMessage());
            return null;
        } finally {
			try {
				conn.close();
				st.close();
				rs.close();
			} catch (SQLException e) {
				System.out.println("连接池关闭失败！");
			}
		}
    }
    
    
    //更新插入token进入数据库
    public void updateAccessToken(String accesstoken){
    	JDBCUtil ju=new JDBCUtil();
    	conn=ju.connect();
		try {
			String sql="update wxtoken set token=?,freshtime=?";
			st=(PreparedStatement) conn.prepareStatement(sql); 
			st.setString(1, accesstoken);
			st.setString(2, getSystime());
			st.executeUpdate();
			System.out.println("更新accesstoken成功！");
		} catch (SQLException e) {  
            System.out.println("更新accesstoken失败！" + e.getMessage());
		} finally {
			try {
				conn.close();
				st.close();
			} catch (SQLException e) {
				System.out.println("连接池关闭失败！");
			}
		}
    }
    
    //取出accesstoken
    public String getAccesstoken(){
    	String result="";
    	JDBCUtil ju=new JDBCUtil();
		conn=ju.connect();
		try {  
            String sql = "select * from wxtoken";  
            st = (PreparedStatement) conn.prepareStatement(sql);  
            rs = st.executeQuery();
            while (rs.next()) {
            	result=rs.getString("token");
            }
            return result;
        } catch (SQLException e) {  
            System.out.println("获取token值失败："+e.getMessage());
            return null;
        } finally {
			try {
				conn.close();
				st.close();
				rs.close();
			} catch (SQLException e) {
				System.out.println("连接池关闭失败！");
			}
		}
    }
    
    //验证用户openid是否已经绑定
    public String getUserMobile(String openid){
    	String result="";
    	JDBCUtil ju=new JDBCUtil();
		conn=ju.connect();
		try {  
            String sql = "select mobile from fyuser where openid=?";  
            st = (PreparedStatement) conn.prepareStatement(sql);  
            st.setString(1, openid);
            rs = st.executeQuery();
            while (rs.next()) {
            	result=rs.getString("mobile");
            }
            return result;
        } catch (SQLException e) {  
            System.out.println("获取mobile值失败："+e.getMessage());
            return null;
        } finally {
			try {
				conn.close();
				st.close();
				rs.close();
			} catch (SQLException e) {
				System.out.println("连接池关闭失败！");
			}
		}
    }
    
  //验证用户mobile是否已经做过绑定使用
    public String getMobileBand(String mobile){
    	String result="";
    	JDBCUtil ju=new JDBCUtil();
		conn=ju.connect();
		try {  
            String sql = "select mobile from fyuser where mobile=?";  
            st = (PreparedStatement) conn.prepareStatement(sql);  
            st.setString(1, mobile);
            rs = st.executeQuery();
            while (rs.next()) {
            	result=rs.getString("mobile");
            }
            return result;
        } catch (SQLException e) {  
            System.out.println("获取mobile值失败："+e.getMessage());
            return null;
        } finally {
			try {
				conn.close();
				st.close();
				rs.close();
			} catch (SQLException e) {
				System.out.println("连接池关闭失败！");
			}
		}
    }
    
    
    //插入未绑定用户信息
    public void insertUser(String openid,String mobile,String belong,String operator,String fname,String school,String building,String schoolyear,String schoolmajor){
    	JDBCUtil ju=new JDBCUtil();
		conn=ju.connect();
		try {  
            String sql = "insert into fyuser(openid,experience,points,level,nickname,mobile,belong,operator,fname,school,schoolbuilding,schoolgrade,schoolmajor,headimg,bindingtime,subscribetime) "
            		+ "values(?,80,80,'--','',?,?,?,?,?,?,?,?,'',?,'')";  
            st = (PreparedStatement) conn.prepareStatement(sql); 
            st.setString(1, openid);
            st.setString(2, mobile);
            st.setString(3, belong);
            st.setString(4, operator);
            st.setString(5, fname);
            st.setString(6, school);
            st.setString(7, building);
            st.setString(8, schoolyear);
            st.setString(9, schoolmajor);
            st.setString(10, getSystime()+"--214");
            int count = st.executeUpdate(); 
//            System.out.println("写入fyuser用户绑定信息" + count + " 条数据"); 
        } catch (SQLException e) {  
            System.out.println("写入fyuser用户绑定信息失败" + e.getMessage());  
        } finally {
			try {
				conn.close();
				st.close();
			} catch (SQLException e) {
				System.out.println("连接池关闭失败！");
			}
		}  
    }
    
  //验证用户school是否为young认证学校
    public String getSchoolBand(String school){
    	String result="";
    	JDBCUtil ju=new JDBCUtil();
		conn=ju.connect();
		try {  
            String sql = "select shname from fyschool where shname=?";  
            st = (PreparedStatement) conn.prepareStatement(sql);  
            st.setString(1, school);
            rs = st.executeQuery();
            while (rs.next()) {
            	result=rs.getString("shname");
            }
            return result;
        } catch (SQLException e) {  
            System.out.println("获取认证校园库school值失败："+e.getMessage());
            return null;
        } finally {
			try {
				conn.close();
				st.close();
				rs.close();
			} catch (SQLException e) {
				System.out.println("连接池关闭失败！");
			}
		}
    }
    
    public Map getFyUserinfoMap(String openid){
    	map=new HashMap();
    	JDBCUtil ju=new JDBCUtil();
		conn=ju.connect();
		try {  
            String sql = "select nickname,experience,points,level,mobile,school,schoolbuilding,fname,schoolgrade,schoolmajor,headimg from fyuser where openid=?";  
            st = (PreparedStatement) conn.prepareStatement(sql); 
            st.setString(1, openid);
            rs = st.executeQuery();
            while (rs.next()) {
            	map.put("nickname", rs.getString("nickname"));
            	map.put("experience", rs.getInt("experience"));
            	map.put("points", rs.getInt("points"));
            	map.put("level", rs.getString("level"));
            	map.put("mobile", rs.getString("mobile"));
            	map.put("school", rs.getString("school"));
            	map.put("building", rs.getString("schoolbuilding"));
            	map.put("name", rs.getString("fname"));
            	map.put("grade", rs.getString("schoolgrade"));
            	map.put("major", rs.getString("schoolmajor"));
            	map.put("headimg", rs.getString("headimg"));
            }
            return map;
        } catch (SQLException e) {  
            System.out.println("获取fyuser所有信息值失败："+e.getMessage());
            return null;
        } finally {
			try {
				conn.close();
				st.close();
				rs.close();
			} catch (SQLException e) {
				System.out.println("连接池关闭失败！");
			}
		}
    }
    
    public void UpdateNicknameHeadimg(String nickname,String headimg,String openid,String subscribetime){
    	JDBCUtil ju=new JDBCUtil();
    	conn=ju.connect();
		try {
			String sql="update fyuser set nickname=?,headimg=?,subscribetime=? where openid=?";
			st=(PreparedStatement) conn.prepareStatement(sql); 
			st.setString(1, nickname);
            st.setString(2, headimg);
            st.setString(3, subscribetime);
            st.setString(4, openid);
			st.executeUpdate();
//			System.out.println("更新关注时间-用户昵称和头像成功！");
		} catch (SQLException e) {  
            System.out.println("更新关注时间-用户昵称和头像失败！" + e.getMessage());
		} finally {
			try {
				conn.close();
				st.close();
			} catch (SQLException e) {
				System.out.println("连接池关闭失败！");
			}
		}
    }
    
    public void UpdateFyUser(String openid,String mobile,String belong,String operator,String name,String school,String building,String grade,String major){
    	JDBCUtil ju=new JDBCUtil();
    	conn=ju.connect();
		try {
			String sql="update fyuser set mobile=?,belong=?,operator=?,fname=?,school=?,schoolbuilding=?,schoolgrade=?,schoolmajor=? where openid=?";
			st=(PreparedStatement) conn.prepareStatement(sql); 
			st.setString(1, mobile);
            st.setString(2, belong);
            st.setString(3, operator);
            st.setString(4, name);
            st.setString(5, school);
            st.setString(6, building);
            st.setString(7, grade);
            st.setString(8, major);
            st.setString(9, openid);
			st.executeUpdate();
//			System.out.println("更新用户信息成功！");
		} catch (SQLException e) {  
            System.out.println("更新用户信息失败！" + e.getMessage());
		} finally {
			try {
				conn.close();
				st.close();
			} catch (SQLException e) {
				System.out.println("连接池关闭失败！");
			}
		}
    }
    
  //删除已占有mobile用户绑定信息
    public void deleteMobileBand(String mobile){
    	JDBCUtil ju=new JDBCUtil();
		conn=ju.connect();
		try {  
            String sql = "delete from fyuser where mobile=?";  
            st = (PreparedStatement) conn.prepareStatement(sql);  
            st.setString(1, mobile);
            st.executeUpdate();
//            System.out.println("解绑删除用户信息成功！");
        } catch (SQLException e) {  
            System.out.println("解绑删除用户信息失败："+e.getMessage());
        } finally {
			try {
				conn.close();
				st.close();
			} catch (SQLException e) {
				System.out.println("连接池关闭失败！");
			}
		}
    }
    
  //删除已占有mobile用户绑定信息
    public void deleteMobileBandByOpenid(String mobile ,String openid){
    	JDBCUtil ju=new JDBCUtil();
		conn=ju.connect();
		try {  
            String sql = "delete from fyuser where mobile=? and openid<>?";  
            st = (PreparedStatement) conn.prepareStatement(sql);  
            st.setString(1, mobile);
            st.setString(2, openid);
            st.executeUpdate();
//            System.out.println("解绑删除更换手机号用户信息成功！");
        } catch (SQLException e) {  
            System.out.println("解绑删除更换手机号用户信息失败："+e.getMessage());
        } finally {
			try {
				conn.close();
				st.close();
			} catch (SQLException e) {
				System.out.println("连接池关闭失败！");
			}
		}
    }
    
    /**
    * 
    * @param 注销用户
    * @return
    */
    
    //查询注销用户信息
    public Map selectFyUserinfoMapAll(String openid){
    	map=new HashMap();
    	JDBCUtil ju=new JDBCUtil();
		conn=ju.connect();
		try {  
            String sql = "select openid,experience,points,level,nickname,mobile,belong,operator,fname,school,schoolbuilding,schoolgrade,schoolmajor,headimg,bindingtime,subscribetime from fyuser where openid=?";  
            st = (PreparedStatement) conn.prepareStatement(sql); 
            st.setString(1, openid);
            rs = st.executeQuery();
            while (rs.next()) {
            	map.put("openid", rs.getString("openid"));
            	map.put("experience", rs.getInt("experience"));
            	map.put("points", rs.getInt("points"));
            	map.put("level", rs.getString("level"));
            	map.put("nickname", rs.getString("nickname"));
            	map.put("mobile", rs.getString("mobile"));
            	map.put("belong", rs.getString("belong"));
            	map.put("operator", rs.getString("operator"));
            	map.put("fname", rs.getString("fname"));
            	map.put("school", rs.getString("school"));
            	map.put("schoolbuilding", rs.getString("schoolbuilding"));
            	map.put("schoolgrade", rs.getString("schoolgrade"));
            	map.put("schoolmajor", rs.getString("schoolmajor"));
            	map.put("headimg", rs.getString("headimg"));
            	map.put("bindingtime", rs.getString("bindingtime"));
            	map.put("subscribetime", rs.getString("subscribetime"));
            }
            return map;
        } catch (SQLException e) {  
            System.out.println("获取注销fyuser所有信息值失败："+e.getMessage());
            return null;
        } finally {
			try {
				conn.close();
				st.close();
				rs.close();
			} catch (SQLException e) {
				System.out.println("连接池关闭失败！");
			}
		}
    }
    
    //插入注销用户信息
    public void insertCancelUser(String openid,int experience,int points,String level,String nickname,String mobile,String belong,String operator,String fname,String school,String schoolbuilding,String schoolgrade,String schoolmajor,String headimg,String bindingtime,String subscribetime){
    	JDBCUtil ju=new JDBCUtil();
		conn=ju.connect();
		try {  
            String sql = "insert into fyuser_archive(openid,experience,points,level,nickname,mobile,belong,operator,fname,school,schoolbuilding,schoolgrade,schoolmajor,headimg,bindingtime,subscribetime,archivetime) "
            		+ "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";  
            st = (PreparedStatement) conn.prepareStatement(sql);  
            st.setString(1, openid);
            st.setInt(2, experience);
            st.setInt(3, points);
            st.setString(4, level);
            st.setString(5, nickname);
            st.setString(6, mobile);
            st.setString(7, belong);
            st.setString(8, operator);
            st.setString(9, fname);
            st.setString(10, school);
            st.setString(11, schoolbuilding);
            st.setString(12, schoolgrade);
            st.setString(13, schoolmajor);
            st.setString(14, headimg);
            st.setString(15, bindingtime);
            st.setString(16, subscribetime);
            st.setString(17, getSystime());
            st.executeUpdate(); 
//            System.out.println("写入fyuser注销用户绑定信息"); 
        } catch (SQLException e) {  
            System.out.println("写入fyuser注销用户绑定信息失败" + e.getMessage());  
        } finally {
			try {
				conn.close();
				st.close();
			} catch (SQLException e) {
				System.out.println("连接池关闭失败！");
			}
		}  
    }
    
    //删除已注销用户绑定信息
    public void deleteCancelUser(String openid){
    	JDBCUtil ju=new JDBCUtil();
		conn=ju.connect();
		try {  
            String sql = "delete from fyuser where openid=?";
            st = (PreparedStatement) conn.prepareStatement(sql);  
            st.setString(1, openid);
            st.executeUpdate();
//            System.out.println("解绑删除注销用户信息成功！");
        } catch (SQLException e) {  
            System.out.println("解绑删除注销用户信息失败："+e.getMessage());
        } finally {
			try {
				conn.close();
				st.close();
			} catch (SQLException e) {
				System.out.println("连接池关闭失败！");
			}
		}
    }
    
    //查询校园店信息
    public List checkSchoolShop(){
    	list=new ArrayList();
    	JDBCUtil ju=new JDBCUtil();
		conn=ju.connect();
		try {  
            String sql = "select shname,shem,sharea,shimg,spname,sptype,spagent,spaddress,sptel,spcharge,spmobile,spemail,spbusinesshour from fyschoolshop group by shname order by id";  
            st = (PreparedStatement) conn.prepareStatement(sql);  
            rs = st.executeQuery();
            while (rs.next()) {
            	map=new HashedMap();
            	map.put("schoolname", rs.getString("shname").trim());
            	map.put("schoolem", rs.getString("shem").trim());
            	map.put("region", rs.getString("sharea").trim());
            	map.put("shimage", rs.getString("shimg").trim());
            	map.put("shopname", rs.getString("spname").trim());
            	map.put("shoptype", rs.getString("sptype").trim());
            	map.put("shopagent", rs.getString("spagent").trim());
            	map.put("shopaddress", rs.getString("spaddress").trim());
            	map.put("shoptel", rs.getString("sptel").trim());
            	map.put("shopcharge", rs.getString("spcharge").trim());
            	map.put("shopmobile", rs.getString("spmobile").trim());
            	map.put("shopemail", rs.getString("spemail").trim());
            	map.put("shopbusinesshour", rs.getString("spbusinesshour").trim());
                list.add(map);
            }
            return list;
        } catch (SQLException e) {  
            System.out.println("查询校园店信息："+e.getMessage());
            return null;
        } finally {
			try {
				conn.close();
				st.close();
				rs.close();
			} catch (SQLException e) {
				System.out.println("连接池关闭失败！");
			}
		}
    }
    
    //条件查询校园店---已绑定young粉
    public Map checkSchoolShopBySchool(String school){
    	map=new HashMap();
    	JDBCUtil ju=new JDBCUtil();
		conn=ju.connect();
		try {  
            String sql = "select shname,shem,sharea,shimg,spname,sptype,spagent,spaddress,sptel,spcharge,spmobile,spemail,spbusinesshour from fyschoolshop where shname=?";  
            st = (PreparedStatement) conn.prepareStatement(sql); 
            st.setString(1, school);
            rs = st.executeQuery();
            while (rs.next()) {
            	map.put("schoolname", rs.getString("shname").trim());
            	map.put("schoolem", rs.getString("shem").trim());
            	map.put("region", rs.getString("sharea").trim());
            	map.put("shimage", rs.getString("shimg").trim());
            	map.put("shopname", rs.getString("spname").trim());
            	map.put("shoptype", rs.getString("sptype").trim());
            	map.put("shopagent", rs.getString("spagent").trim());
            	map.put("shopaddress", rs.getString("spaddress").trim());
            	map.put("shoptel", rs.getString("sptel").trim());
            	map.put("shopcharge", rs.getString("spcharge").trim());
            	map.put("shopmobile", rs.getString("spmobile").trim());
            	map.put("shopemail", rs.getString("spemail").trim());
            	map.put("shopbusinesshour", rs.getString("spbusinesshour").trim());
            }
            return map;
        } catch (SQLException e) {  
            System.out.println("获取已绑定学校校园店失败："+e.getMessage());
            return null;
        } finally {
			try {
				conn.close();
				st.close();
				rs.close();
			} catch (SQLException e) {
				System.out.println("连接池关闭失败！");
			}
		}
    }
    
  //遍历所有学校
    public List checkSchoolAll(){
    	list=new ArrayList();
    	JDBCUtil ju=new JDBCUtil();
		conn=ju.connect();
		try {  
            String sql = "select shname from fyschool order by shname desc";  
            st = (PreparedStatement) conn.prepareStatement(sql); 
            rs = st.executeQuery();
            while (rs.next()) {
            	list.add(rs.getString("shname").trim());
            }
            return list;
        } catch (SQLException e) {  
            System.out.println("获取所有学校失败："+e.getMessage());
            return null;
        } finally {
			try {
				conn.close();
				st.close();
				rs.close();
			} catch (SQLException e) {
				System.out.println("连接池关闭失败！");
			}
		}
    }
    
  //遍历所有学校对应楼的关系
    public List checkFloorBySchool(String school){
    	list=new ArrayList();
    	JDBCUtil ju=new JDBCUtil();
		conn=ju.connect();
		try {  
            String sql = "select bdname from fycaptian where shname=?";  
            st = (PreparedStatement) conn.prepareStatement(sql); 
            st.setString(1, school);
            rs = st.executeQuery();
            while (rs.next()) {
            	list.add(rs.getString("bdname").trim());
            }
            return list;
        } catch (SQLException e) {  
            System.out.println("获取对应学校楼信息失败："+e.getMessage());
            return null;
        } finally {
			try {
				conn.close();
				st.close();
				rs.close();
			} catch (SQLException e) {
				System.out.println("连接池关闭失败！");
			}
		}
    }
    
  //积分使用记录
    public void savePointsEvent(String openid,String product,String events,String points){
    	JDBCUtil ju=new JDBCUtil();
		conn=ju.connect();
		try {  
            String sql = "insert into fyevents(openid,product,events,points,logtime) "
            		+ "values(?,?,?,?,?)";  
            st = (PreparedStatement) conn.prepareStatement(sql); 
            st.setString(1, openid);
            st.setString(2, product);
            st.setString(3, events);
            st.setString(4, points);
			st.setString(5, getSystime());
            int count = st.executeUpdate(); 
//            System.out.println("写入fyuser用户使用积分记录信息" + count + " 条数据"); 
        } catch (SQLException e) {  
            System.out.println("写入fyuser用户使用积分记录信息失败" + e.getMessage());  
        } finally {
			try {
				conn.close();
				st.close();
			} catch (SQLException e) {
				System.out.println("连接池关闭失败！");
			}
		}  
    }
    
  //积分使用记录
    public List checkPointsEvent(String openid){
    	list=new ArrayList();
    	JDBCUtil ju=new JDBCUtil();
		conn=ju.connect();
		try {  
            String sql = "select product,events,points,logtime from fyevents where openid=?";  
            st = (PreparedStatement) conn.prepareStatement(sql); 
            st.setString(1, openid);
            rs = st.executeQuery();
            while (rs.next()) {
            	map=new HashedMap();
            	map.put("product", rs.getString("product").trim());
            	map.put("events", rs.getString("events").trim());
            	map.put("points", rs.getString("points").trim());
            	map.put("logtime", rs.getString("logtime").trim());
                list.add(map);
            }
            return list;
        } catch (SQLException e) {  
            System.out.println("查询fyuser用户使用积分记录信息失败" + e.getMessage());  
            return null;
        } finally {
			try {
				conn.close();
				st.close();
				rs.close();
			} catch (SQLException e) {
				System.out.println("连接池关闭失败！");
			}
		}  
    }
    
  //统计商城产品剩余数量
    public int CountProduct(String product,String points){
    	int result=0;
    	JDBCUtil ju=new JDBCUtil();
		conn=ju.connect();
		try {  
            String sql = "SELECT COUNT(*) FROM fyevents WHERE product=? and points=?";  
            st = (PreparedStatement) conn.prepareStatement(sql);
            st.setString(1, product);
            st.setString(2, points);
            rs = st.executeQuery();
            while (rs.next()) {
            	result=rs.getInt("COUNT(*)");
            }
            return result;
        } catch (SQLException e) {  
            System.out.println("获取商品兑换次数统计count值失败："+e.getMessage());
            return result;
        } finally {
			try {
				conn.close();
				st.close();
				rs.close();
			} catch (SQLException e) {
				System.out.println("连接池关闭失败！");
			}
		}  
    }
    
  //统计商城产品兑换数量
    public int CountProductByOpenid(String openid){
    	int result=0;
    	JDBCUtil ju=new JDBCUtil();
		conn=ju.connect();
		try {  
            String sql = "SELECT COUNT(*) FROM fyevents WHERE openid=? and product<>''";  
            st = (PreparedStatement) conn.prepareStatement(sql);
            st.setString(1, openid);
            rs = st.executeQuery();
            while (rs.next()) {
            	result=rs.getInt("COUNT(*)");
            }
            return result;
        } catch (SQLException e) {  
            System.out.println("获取商品兑换次数统计count值失败："+e.getMessage());
            return result;
        } finally {
			try {
				conn.close();
				st.close();
				rs.close();
			} catch (SQLException e) {
				System.out.println("连接池关闭失败！");
			}
		}  
    }
    
    //更新积分使用明细
    public void UpdatePointsUse(String openid,int points){
    	JDBCUtil ju=new JDBCUtil();
    	conn=ju.connect();
		try {
			String sql="update fyuser set points=points-? where openid=?";
			st=(PreparedStatement) conn.prepareStatement(sql); 
			st.setInt(1, points);
            st.setString(2, openid);
			st.executeUpdate();
//			System.out.println("更新积分使用明细扣除成功！");
		} catch (SQLException e) {  
            System.out.println("更新积分使用明细扣除失败！" + e.getMessage());
		} finally {
			try {
				conn.close();
				st.close();
			} catch (SQLException e) {
				System.out.println("连接池关闭失败！");
			}
		}  
    }
    
    //删除已注销用户积分信息
    public void deleteEventsUser(String openid){
    	JDBCUtil ju=new JDBCUtil();
		conn=ju.connect();
		try {  
            String sql = "delete from fyevents where openid=?";
            st = (PreparedStatement) conn.prepareStatement(sql);
            st.setString(1, openid);
            st.executeUpdate();
//            System.out.println("解绑删除注销用户信息成功！");
        } catch (SQLException e) {  
            System.out.println("解绑删除注销用户事件信息失败："+e.getMessage());
        } finally {
			try {
				conn.close();
				st.close();
			} catch (SQLException e) {
				System.out.println("连接池关闭失败！");
			}
		}  
    }
    
  //删除已注销用户签到信息
    public void deleteSignUser(String openid){
    	JDBCUtil ju=new JDBCUtil();
		conn=ju.connect();
		try {  
            String sql = "delete from fysignuser where userid=?";
            st = (PreparedStatement) conn.prepareStatement(sql);
            st.setString(1, openid);
            st.executeUpdate();
//            System.out.println("解绑删除注销用户信息成功！");
        } catch (SQLException e) {  
            System.out.println("解绑删除注销用户签到信息失败："+e.getMessage());
        } finally {
			try {
				conn.close();
				st.close();
			} catch (SQLException e) {
				System.out.println("连接池关闭失败！");
			}
		}  
    }
}
